package cn.inbot.shopadmin.util;

import android.util.Base64;
import android.util.Log;

import java.io.UnsupportedEncodingException;

import cn.inbot.lib.util.StringUtil;

public class Base64Util {

	public static String stringToBase64(String source) {

		if (StringUtil.isEmpty(source)) {
			return source;
		}

		byte[] stringBytes = null;

		try {

			stringBytes = source.getBytes("utf-8");

		} catch (UnsupportedEncodingException e) {
			Log.e("login", "failed to trans password string to bytes");

			return null;
		}

		if (null == stringBytes || stringBytes.length < 1) {
			return null;
		}

		String base64String = Base64.encodeToString(stringBytes,Base64.DEFAULT);

		return base64String;
	}
}
